import java.io.*;

public class Handler {
    private Move move;

    public Handler(Move move) {
        this.move = move;
    }


    public void doCmd(String word, Cube cube) {
    }

    public void keepGoing(int a, int b, Cube cube) {
        cube.keepGoing(a, b);
    }

    public void backStep(Cube cube) {
        if (move.step.size() > 1) {
            move.step.remove(move.step.size() - 1);
            move.gradeStep.remove(move.gradeStep.size() - 1);
            cube.setCube(move.step.get(move.step.size() - 1));
            cube.setGrade(move.gradeStep.get(move.step.size() - 1));
        }
    }



    public int getGrade(Cube cube) {
        return cube.getGrade();
    }

    public boolean getIsMove(Cube cube) {
        return cube.getIsMove();
    }

    public void reborn(Cube cube) {
        cube.newOut();
    }

    public void check(Cube cube) {
        cube.check();
    }

    public boolean getIsOver(Cube cube) {
        return cube.getIsOver();
    }





    public static Cube loadGame() {
        Cube lastCube = new Cube();
        try {
            ObjectInputStream in = new ObjectInputStream(
                    new FileInputStream("cube.dat"));
            lastCube = (Cube) in.readObject();
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lastCube;
    }

    public static void saveGame(Cube cube) {
        try {
            ObjectOutputStream out = new ObjectOutputStream(
                    new FileOutputStream("cube.dat"));
            out.writeObject(cube);
            out.flush();
            out.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}





